package cn.lg.soar.system.auth.service.impl;

import cn.lg.soar.common.util.AssertUtil;
import cn.lg.soar.common.util.current.CurrentProxy;
import cn.lg.soar.database.base.service.impl.BaseServiceImpl;
import cn.lg.soar.system.auth.entity.SsoApply;
import cn.lg.soar.system.auth.mapper.SsoApplyMapper;
import cn.lg.soar.system.auth.service.ISsoApplyService;
import cn.lg.soar.system.config.AuthCacheKey;
import org.springframework.cache.annotation.Cacheable;

import java.io.Serializable;
import java.util.Collection;

/**
 * @author luguoxiang
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
public class SsoApplyServiceImpl extends BaseServiceImpl<SsoApplyMapper, SsoApply>
        implements ISsoApplyService, CurrentProxy<ISsoApplyService> {

    @Cacheable(value = AuthCacheKey.OSS_CLIENT_BY_ID, key = "#id")
    @Override
    public SsoApply getById(Serializable id) {
        SsoApply ssoApply = super.getById(id);
        AssertUtil.notNull(ssoApply, "客户端不存在");
        return ssoApply;
    }

    @Override
    public boolean updateById(SsoApply entity) {
        removeCache(entity.getId());
        return super.updateById(entity);
    }

    @Override
    public boolean removeById(Serializable id) {
        removeCache(id);
        return super.removeById(id);
    }

    @Override
    public boolean removeByIds(Collection<?> list) {
        removeCache(list);
        return super.removeByIds(list);
    }

    @Override
    public void removeCache(Object... ids) {
        evictCache(AuthCacheKey.OSS_CLIENT_BY_ID, ids);
    }

    @Override
    public void clearCache() {
        clearCache(AuthCacheKey.OSS_CLIENT_BY_ID);
    }
}
